package com.jboost.hyk.common.model;

import com.jboost.common.util.DateUtils;
import com.jboost.hyk.common.constant.ValidStatusEnum;
import com.jboost.hyk.common.entity.Category;
import com.jboost.hyk.help.entity.HelpCategory;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
  * 树形列表用到
 */
@Data
public class TreeModel implements Serializable {

	private static final long serialVersionUID = 4013193970046502756L;

	/** ID */
	private String id;
	/** 创建人 */
	private String createBy;
	/** 创建时间 */
	private String createTime;
	/** 更新人 */
	private String updateBy;
	/** 更新时间 */
	@DateTimeFormat(pattern = "yyyy-MM-dd hh:mm:ss")
	private java.util.Date updateTime;

	/**parentId*/
	private String parentId;
	/**code*/
	private String code;
	/**name*/
	private String name;
	/**描述*/
	private String describes;
	@ApiModelProperty(value = "valid-正常；invalid-停用")
	private java.lang.String status;
	private java.lang.String status_dictText;
	/**是否有子节点：0-否；1-是；*/
	private Integer hasChild  ;
	@ApiModelProperty(value = "层级，0开始")
	private Integer grade;

	public String getStatus_dictText() {
		return ValidStatusEnum.getDescByCode(status);
	}

	private Map<String,String> scopedSlots;

	public Map<String, String> getScopedSlots() {
		return scopedSlots;
	}

	public void setScopedSlots(Map<String, String> scopedSlots) {
		this.scopedSlots = scopedSlots;
	}



	private List<TreeModel> children;

	public List<TreeModel> getChildren() {
		return children;
	}

	public void setChildren(List<TreeModel> children) {
		this.children = children;
	}

	public TreeModel() {

	}

	public TreeModel(Category category) {
		BeanUtils.copyProperties(category,this);
		this.setCreateTime(DateUtils.formatDate(category.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
		if(null!=category.getHasChild() && 1==category.getHasChild()) {
			this.children = new ArrayList<TreeModel>();
		}
	}
	public TreeModel(HelpCategory category) {
		BeanUtils.copyProperties(category,this);
		this.setCreateTime(DateUtils.formatDate(category.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
		if(null!=category.getHasChild() && 1==category.getHasChild()) {
			this.children = new ArrayList<TreeModel>();
		}
	}


}
